#include "tetris.h"

/*float xinc=1.6f, yinc=1.0f;
float x=0, y=0;
*/

void render() {	
	xr->draw(); 
/*	for (int i=0; i<sizeof(blokken); i++)
	{
		blokken[i].draw();
	}
*/
	// draw fps
	xr->drawText(0,0,"FPS: 20");
		glutSwapBuffers();

}
void resize(GLsizei w, GLsizei h) { xr->resize(w, h); }

void initTetris()
{
	blokken = new TetrisBlok[50];
}

void tetrisLogic(int arg)
{
	for (int i=0; i < sizeof(blokken); i++)
	{
		// do
	}
}

void mainLoop()
{
	static double dFrames = 0;
	unsigned int iTimePassed = 0;
	static unsigned int iLastTime = 0;
	double fps = 0;

	dFrames++;

	iTimePassed = glutGet(GLUT_ELAPSED_TIME);

	if (iTimePassed - iLastTime >= 1000)
	{	
		//
		fps = dFrames;//*1000.0f/(iTimePassed - iLastTime);
		printf("FPS: %5.3f\n",fps);
		dFrames = 0;
		iLastTime = iTimePassed;

	}
	/*
	frame++;		
	timepassed = glutGet(GLUT_ELAPSED_TIME);
	if(timepassed - timebase > 1000)
	{
		fps = frame*1000.0/(timepassed-timebase);
		printf("%5.3f fps\n", fps);
		timebase = timepassed;
		frame = 0;
	}



	   */

	render(); // Render the frame!
}

int main(int argc, char* argv[])
{
	xr = new xRender();
	// Init glut with args
	glutInit(&argc, argv);

	// Double buffering & colour (NOT COLOR)
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);

	// Create window
	glutInitWindowSize(800, 600);
	glutCreateWindow("xTetris");
	

	// render function
	glutDisplayFunc(render);

	// resize function
	glutReshapeFunc(resize);

	glutIdleFunc(mainLoop);

	// Setup some stuff
	xr->setupRC();

	initTetris();

	tetrisLogic(0);

	// main loop
	glutMainLoop();

	// we never reach this
	return 0;
}